import time

from selenium.webdriver.common.by import By

from xinan_ui.proxy.base_page import PageHandle
from xinan_ui.tools.read_yml_xn import ReadYaml
from xinan_ui.tools.swipe_pro import SwipeTool
import logging
data_eles = ReadYaml(r'D:\testLi\PythonWork\xinan_ui\config\jdzapp.yml').read_yaml()['普通买入']

class PtBuy(PageHandle):
    def __init__(self,driver):
        self.driver=driver
        super().__init__(self.driver)

    def pt_buy(self,code,amount):
        #点击买入入口
        self.click_button(data_eles[0]['买入入口按钮'])
        time.sleep(5)
        #卖买标题
        self.click_button(data_eles[10]['卖出标题'])
        time.sleep(1)
        self.click_button(data_eles[11]['买入标题'])
        time.sleep(2)

        #点击股票代码输入框
        self.click_button(data_eles[1]['股票代码输入框'])
        time.sleep(2)
        #输入代码
        self.input_element(data_eles[1]['股票代码输入框'],code)
        time.sleep(2)
        #点击键盘确定按钮
        self.click_button(data_eles[3]['目标代码按钮'])
        time.sleep(2)
        #数量输入
        self.input_element(data_eles[4]['数量输入框'],amount)
        time.sleep(2)
        #点击买入
        self.click_button(data_eles[5]['买入按钮'])
        time.sleep(2)
        print(self.get_text(data_eles[9]['买入委托弹窗提示文案']))
        time.sleep(2)
        #点击确定买入
        self.click_button(data_eles[12]['买入委托弹窗确定买入按钮'])
        time.sleep(2)
        #点击委托信息确定按钮
        act=self.get_text(data_eles[13]['委托系统信息弹窗文案'])
        self.click_button(data_eles[14]['委托系统信息弹窗确定按钮'])
        time.sleep(2)
        #返回上级菜单
        self.click_button(data_eles[8]['返回上级'])
        time.sleep(2)
        logging.info(f"-{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}-本次买入的代码为{code},数量为{amount}")
        return act







